//
//  SeekController.m
//  HandheldHospital
//
//  Created by 张鹏的电脑 on 16/2/29.
//  Copyright © 2016年 zhangchao. All rights reserved.
//

#import "SeekController.h"
#import "SeekCell.h"
//#import "SeekModel.h"
#import "ChatController.h"


@interface SeekController ()<UISearchBarDelegate>

@property(nonatomic,strong)NSMutableArray *Seekarray;

@property (nonatomic,strong) NSMutableArray *dataArray;
@property (nonatomic,strong) NSMutableArray *filterArray;
@property (nonatomic,strong) UISearchBar *searchBar;

@end

@implementation SeekController
- (NSMutableArray *)dataArray
{
    if(_dataArray == nil)
    {
        _dataArray = [NSMutableArray arrayWithArray:self.Seekarray];
    }
    return _dataArray;
}



-(NSMutableArray *)Seekarray{
    if (!_Seekarray) {
       
        _Seekarray = [NSMutableArray array];
        
        NSMutableArray *arrayM = [NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"yisheng.plist" ofType:nil]];
//        for (NSDictionary *dict in arrayM) {
//            SeekModel *model = [[SeekModel alloc]initWithDic:dict];
//            [_Seekarray addObject:model];
//            
//        }

    
    }
    
    return _Seekarray;
    
}



- (void)viewDidLoad {
    [super viewDidLoad];
    //隐藏tabBar
    self.tabBarController.tabBar.hidden = YES;
    //设置tableView大小
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20,[UIScreen  mainScreen].bounds.size.width ,[UIScreen  mainScreen].bounds.size.height)];
    self.searchBar  = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 20, self.tableView.frame.size.width, 44)];
    [self.tableView addSubview:self.searchBar];
    self.searchBar.delegate = self;
    
   
    //注册 cell
    [self.tableView registerNib:[UINib nibWithNibName:@"SeekCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    //设置代理
     self.tableView.tableHeaderView = self.searchBar;
}




#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    return self.dataArray.count;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return @"附近热门医生";
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 150;
    
}

- (NSMutableArray *)filterArray{
    
    if (!_filterArray) {
        _filterArray = [NSMutableArray array];
        
    }
    return _filterArray;
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SeekCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    
    
//    SeekModel *sem = self.dataArray[indexPath.row];
//    
//    cell.nameLable.text = sem.name;
//    cell.yiyuanLabel.text = sem.yiyuan;
//    cell.zhichenglabel.text = sem.zhicheng;
//    cell.keLeiLabel.text = sem.kelei;
    
    
    return cell;
    
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    NSString *str = searchBar.text;
    NSPredicate *preicate = [NSPredicate predicateWithFormat:@"name LIKE %@", str];
    if (self.filterArray!= nil) {
        [self.filterArray removeAllObjects];
    }
    //过滤数据
    self.filterArray= [NSMutableArray arrayWithArray:[self.Seekarray filteredArrayUsingPredicate:preicate]];
    if(self.dataArray != nil)
    {
        [self.dataArray removeAllObjects];
    }
    self.dataArray = self.filterArray;
    //刷新表格
    [self.tableView reloadData];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ChatController *cc = [[ChatController alloc] init];
    
    [self.navigationController pushViewController:cc animated:YES];
    
    
}





@end
